home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfcookie.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.7 KB  |  72 lines

  1. <!--- This example shows how to set a CFCOOKIE variable,
  2. and also how to delete that variable --->
  3.  
  4. <!--- First select a group of users who have entered
  5. comments into the sample database --->
  6. <CFQUERY NAME="GetAolUser" DATASOURCE="cfsnippets">
  7. SELECT   EMail, FromUser, Subject, Posted
  8. FROM     Comments
  9. </CFQUERY>
  10.  
  11.  
  12.  
  13. <HTML>
  14.  
  15. <HEAD>
  16. <TITLE>
  17. CFCOOKIE Example
  18. </TITLE>
  19. </HEAD>
  20.  
  21. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  22. <BODY  bgcolor="#FFFFD5">
  23.  
  24. <H3>CFCOOKIE Example</H3>
  25.  
  26. <!--- if the url variable delcookie exists,
  27. set the cookie's expiration date to NOW --->
  28.  
  29. <CFIF IsDefined("url.delcookie") is True>
  30.     <CFCOOKIE NAME="TimeVisited"
  31.     VALUE="#Now()#"
  32.     EXPIRES="NOW">        
  33.  
  34. <CFELSE>
  35. <!--- Otherwise, loop through the list of visitors,
  36. and stop when you match the string aol.com in the
  37. visitor's email address --->
  38.  
  39. <CFLOOP QUERY="GetAOLUser">
  40.     <CFIF FindNoCase("aol.com", Email, 1) is not 0>
  41.         <CFCOOKIE NAME="LastAOLVisitor"
  42.         VALUE="#Email#"
  43.         EXPIRES="NOW" >        
  44.     
  45.     </CFIF>
  46. </CFLOOP>
  47.  
  48. <!--- If the timeVisited cookie is not set,
  49. set a value --->
  50.  
  51.     <CFIF IsDefined("Cookie.TimeVisited") is False>
  52.         <CFCOOKIE NAME="TimeVisited"
  53.         VALUE="#Now()#"
  54.         EXPIRES="10">
  55.     </CFIF>
  56. </CFIF>
  57. <!--- show the most recent cookie set --->
  58. <CFIF IsDefined("Cookie.LastAOLVisitor") is "True">
  59.     <P>The last AOL visitor to view this site was
  60.     <CFOUTPUT>#Cookie.LastAOLVisitor#</CFOUTPUT>, on
  61.     <CFOUTPUT>#DateFormat(COOKIE.TimeVisited)#</CFOUTPUT>
  62. <!--- use this link to reset the cookies --->
  63. <P><a href="cfcookie.cfm?delcookie=yes">Hide my tracks</A>
  64.  
  65. <CFELSE>
  66.     <P>No AOL Visitors have viewed the site lately.
  67. </CFIF>
  68.  
  69. </BODY>
  70.  
  71. </HTML>       
  72.